<?php
  include ('header.php');
?>
<head>
<title>Добавление материальной ценности</title>
</head>

<?PHP
/*
foreach ($_POST as $key=>$val) {
echo $key ."|". $val . "<br />";}
*/

 if (isset($_POST['add']) and $_POST['add']) {
 $_POST['one_cost']= str_replace(",",".",$_POST['one_cost']);
 if ($_GET['inv_number']){
 edit_record ($_POST['item_name'],$_POST['code'], $_POST['another_name'],$_POST['nom_number'],$_POST['sn_internal'],$_POST['sub_rah'], $_POST['data_open'], $_POST['ed_code'],$_POST['ed_type'],
 $_POST['inv_numb'], $_POST['count'], $_POST['one_cost'], $_POST['manage'], $_POST['status'],$_POST['auditory'], $_POST['item_type'],$_POST['comment'],$_GET['inv_number']);

 }else{
edit_record ($_POST['item_name'], $_POST['code'],$_POST['another_name'],$_POST['nom_number'],$_POST['sn_internal'],$_POST['sub_rah'], $_POST['data_open'], $_POST['ed_code'], $_POST['ed_type'],
 $_POST['inv_numb'], $_POST['count'], $_POST['one_cost'], $_POST['manage'], $_POST['status'], $_POST['auditory'],$_POST['item_type'],$_POST['comment']); 
 }
 $_GET['inv_number']=$_POST['inv_numb'];
}

$sql="SELECT * FROM all_inventory where inv_numb='".$_GET['inv_number']."'";  
$process=mysql_query($sql, $db);
$row = mysql_fetch_array($process);
?>

<body>
<form name="add_item" action="item_all_inventory.php?inv_number=<?php echo $row[inv_numb]?>" method="post" width='80%'>
<table class=ALL_INVENTORY_EDIT>
<tr><td class=ALL_INVENTORY_EDIT>

Тип предмету </td><td class=ALL_INVENTORY_EDIT>
<SELECT NAME="item_type" onchange='document.forms["add_item"].submit();'>
<?php 

$sql2="SELECT * FROM inventory_type where type_id<>0 order by type_id";  
$process2=mysql_query($sql2, $db);
$i=1;
while ($row2 = mysql_fetch_array($process2, $i)){

if($row[item_type ]){
$selected=($row2[type_id]==$row[item_type]) ? ' selected' :'';
$currtype=$row[item_type];
}
if ($_POST['item_type']){
$selected=($row2[type_id]==$_POST['item_type']) ? ' selected' :'';
$currtype=$_POST['item_type'];
}else if (!$currtype){$currtype=1;}
echo "<option value='".$row2[type_id]."' ".$selected.">".$row2[type_name]."</option>";
}


?>
</SELECT>
</td></tr>
<tr><td width=250 class=ALL_INVENTORY_EDIT>
Название </td><td class=ALL_INVENTORY_EDIT><input type="text" name="item_name" size=50  value='<?php echo $row[item_name]?>'>
</td></tr>
</td></tr>
<?php
if ($currtype==1 || $currtype==2)
{
?>
<tr><td class=ALL_INVENTORY_EDIT>
Код </td><td class=ALL_INVENTORY_EDIT><input type="text" name="code" size=10 value='<?php echo $row[code]?>'>
</td></tr>
<tr><td width=250 class=ALL_INVENTORY_EDIT>
Назва як воно є</td><td class=ALL_INVENTORY_EDIT><input type="text" name="another_name" size=50  value='<?php echo $row[another_name]?>'>
</td></tr>
<tr><td width=250 class=ALL_INVENTORY_EDIT>
Внутрішні пристрої</td><td class=ALL_INVENTORY_EDIT><input type="text" name="sn_internal" size=20  value='<?php echo $row[sn_internal]?>'>
</td></tr>
<?php
}
?>

<tr><td width=250 class=ALL_INVENTORY_EDIT>
Номенклатурний номер</td><td class=ALL_INVENTORY_EDIT><input type="text" name="nom_number" size=10  value='<?php echo $row[nom_number]?> '>
</td></tr>
<tr><td width=250 class=ALL_INVENTORY_EDIT>
Рахунок,Субрахонок </td><td class=ALL_INVENTORY_EDIT><input type="text" name="sub_rah" size=10  value='<?php echo $row[sub_rah]?> '>
</td></tr>


<tr><td class=ALL_INVENTORY_EDIT>
Создание </td><td class=ALL_INVENTORY_EDIT><input type="text" name="data_open" id="data_open_id" size=15 value='<?php echo $row[date_open]?> '>
</td></tr>

<tr><td class=ALL_INVENTORY_EDIT>
Одиниця виміру, код </td><td class=ALL_INVENTORY_EDIT><input type="text" name="ed_code" size=10 value='<?php echo $row[ed_code]?>'>
</td></tr>
<tr><td class=ALL_INVENTORY_EDIT>
Единица измерения </td><td class=ALL_INVENTORY_EDIT><input type="text" name="ed_type" size=10 value='<?php echo $row[ed_type]?>'>
</td></tr>
<tr><td class=ALL_INVENTORY_EDIT>
Инвентарный номер </td><td class=ALL_INVENTORY_EDIT><input type="text" name="inv_numb"  size=8 value='<?php if ($row[inv_numb])echo $row[inv_numb];else {echo '00000000';}?> '>
</td></tr>
<tr><td class=ALL_INVENTORY_EDIT>
Аудитория </td><td class=ALL_INVENTORY_EDIT>
<SELECT NAME="auditory">
<?php 
$sql2="SELECT * FROM auditories where auditory_id<>0";  
$process2=mysql_query($sql2, $db);
$i=1;
while ($row2 = mysql_fetch_array($process2, $i)){
$selected=($row2[auditory_id]==$row[auditory]) ? ' selected' :'';
echo "<option value='".$row2[auditory_id]."' ".$selected.">".$row2[auditory_name]."</option>";
}
?>
</SELECT>
</td></tr>

<tr><td class=ALL_INVENTORY_EDIT>
Количество </td><td class=ALL_INVENTORY_EDIT><input type="text" name="count" size=10 value='<?php echo $row[count]?> '>
</td></tr>
<tr><td class=ALL_INVENTORY_EDIT>
Цена единицы </td><td class=ALL_INVENTORY_EDIT><input type="text" name="one_cost" size=10 value='<?php echo number_format($row[one_cost], 2, '.', '') ?> '>
</td></tr>
<tr><td class=ALL_INVENTORY_EDIT>
Мат.ответственный</td><td class=ALL_INVENTORY_EDIT> 
<SELECT NAME="manage">
<?php 
$sql2="SELECT * FROM users";  
$process2=mysql_query($sql2, $db);
$i=1;
while ($row2 = mysql_fetch_array($process2, $i)){
$selected=($row2[id]==$row[manage]) ? ' selected' :'';
echo "<option value='".$row2[id]."' ".$selected.">".$row2[real_name]."</option>";
}
?>
</SELECT>


</td></tr>
<tr><td class=ALL_INVENTORY_EDIT>
Статус </td><td class=ALL_INVENTORY_EDIT>
<SELECT NAME="status">
<?php 
$sql2="SELECT * FROM item_status where status_id<>0";  
$process2=mysql_query($sql2, $db);
$i=1;
while ($row2 = mysql_fetch_array($process2, $i)){
$selected=($row2[status_id]==$row[status]) ? ' selected' :'';
echo "<option value='".$row2[status_id]."' ".$selected.">".$row2[status_name]."</option>";
}
?>
</SELECT>
</td></tr>
<tr><td class=ALL_INVENTORY_EDIT valign=top>
Коментарій до змін<br>(не обов'язково)</td><td class=ALL_INVENTORY_EDIT><textarea name="comment" cols="36" rows="3"></textarea>
</td></tr>
</table>
<table class=ALL_INVENTORY_EDIT>
<tr><td align=center>
<input type="submit" value="<?php echo $texts['save'] ?>" name="add">
<input type="button" value="Новий запис" name="new" onClick="javascript:window.location='item_all_inventory.php';">
</tr></td>
</table>
</form>
</body>
 <script type="text/javascript">
$(document).ready(function(){
  // ---- Календарь -----
  $('#data_open_id').attachDatepicker();
});
</script> 
 <?php
  include ('footer.php');
?>
</html>

